<!--
 * @description: 
 * @Date: 2022-10-19 13:26:15
 * @LastEditTime: 2022-11-05 21:09:54
-->
<template>
  <div class="userManager bg-white p-4 rounded-lg">
    <BaseForm :formConfig="formConfig" @submitForm="search"></BaseForm>
    <BaseTable
      class="mt-4"
      :tableList="TbData"
      border
      :page="page"
      :tableConfig="TbConfig"
    ></BaseTable>
  </div>
</template>
<script setup>
import { ref } from "vue";
import BaseTable from "../../components/baseTable/index.vue";
import BaseForm from "../../components/baseForm/index.vue";
import ajax from "../../util/ajax";
import sm from "../../util/sm2";
const formConfig = [
  {
    label: "邮箱搜索",
    alias: "mail",
    type: "input",
    placeholder: "请输入邮箱",
  },
];
let q = {};
const search = (data) => {
  q = data;
  getData();
};
const page = ref({
  current_page: 1,
  per_page: 50,
  total: 0,
  refresh(e) {
    Object.assign(page.value, e);
    getData();
  },
});
const TbData = ref([]);
const TbConfig = [
  {
    prop: "id",
    name: "ID",
    align: "center",
    width: 100,
  },
  {
    prop: "mail",
    name: "邮箱账号",
    align: "center",
  },
  {
    prop: "createtime",
    type: "time",
    align: "center",
    name: "创建时间",
  },
  {
    prop: "manager",
    name: "权限",
    align: "center",
    width: 100,
    format(row) {
      if (row.manager == 1) {
        return '<span class="text-red-400">管理员</span>';
      }
      return '<span class="text-blue-400">用户</span>';
    },
  },
  {
    type: "control",
    name: "操作",
    align: "center",
    width: 150,
    button: [
      {
        typeof: "primary",
        size: "small",
        text: "发送邮件",
        click(e) {},
      },
    ],
  },
];
const getData = () => {
  ajax({
    url: "/admin/UserList",
    method: "post",
    data: {
      ...q,
      page: page.value.current_page,
      limit: page.value.per_page,
    },
  }).then((el) => {
    let dt = JSON.parse(sm.decode(el.data));
    TbData.value = dt.data;
    Object.assign(page.value, dt);
  });
};
getData();
</script>
